home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / Icon 8.1 / mep2 / MemMon 2.0 / Samples / concord.icn < prev    next >
Encoding:
Text File  |  1990-01-15  |  1.2 KB  |  44 lines  |  [TEXT/PICN]

  1. #    CONCORD
  2. #
  3. #    Concordance
  4. #
  5. #    Ralph E. Griswold
  6. #
  7. #    Last modified 12/15/85
  8. #
  9. #
  10. #   Set Program Input to concord.dat prior to running.
  11. #
  12.  
  13. procedure main()
  14.    local letters, line, wordlist, word, words, maxword, lineno, i
  15.    local j, lines, numbers
  16.    letters := &lcase ++ &ucase ++ '\''
  17.    words := table("")
  18.    maxword := lineno := 0
  19.    while line := read() do {
  20.       lineno +:= 1
  21.       write(right(lineno,6),"  ",line)
  22.       line := map(line)                # fold to lowercase
  23.       i := 1
  24.       while j := upto(letters,line,i) do {
  25.          i := many(letters,line,j)
  26.          word := line[j:i]
  27.          if *word < 3 then next            # skip short words
  28.          maxword <:= *word            # keep track of longest word
  29.                         # if it's a new word, start set
  30.          if *words[word] = 0 then words[word] := set([lineno])
  31.          else insert(words[word],lineno)    # else add the line number
  32.          }
  33.       }
  34.    write()
  35.    wordlist := sort(words)            # sort by words
  36.    i := 0
  37.    while word := wordlist[i +:= 1][1] do {
  38.       lines := ""                # build up line numbers
  39.       numbers := sort(wordlist[i][2])
  40.       while lines ||:= get(numbers) || ", "
  41.       write(left(word,maxword + 2),": ",lines[1:-2])
  42.       }
  43. end
  44.